package route

import (
	"github.com/gin-gonic/gin"
	"gm/app/controller/active"
	_chan "gm/app/controller/chan"
	"gm/app/controller/jaeger_conn"
	"gm/app/controller/test"
	"gm/app/controller/ws.go"
	"gm/app/route/middleware/cors"
	"gm/app/route/middleware/exception"
	"gm/app/route/middleware/jaeger"
	"gm/app/route/middleware/jwt"
	"gm/app/route/middleware/limiter"
	"gm/app/route/middleware/logger"
	"gm/app/route/middleware/requestid"
	"gm/app/util/response"
)

func SetupRouter(engine *gin.Engine) {

	//设置路由中间件
	engine.Use(logger.SetUp(), exception.SetUp(), jaeger.SetUp())

	//404
	engine.NoRoute(func(c *gin.Context) {
		utilGin := response.Gin{Ctx: c}
		utilGin.Response(404,"请求方法不存在", nil)
	})

	engine.GET("/ping", func(c *gin.Context) {
		utilGin := response.Gin{Ctx: c}
		utilGin.Response(1,"pong", nil)
	})

	// 测试链路追踪
	engine.GET("/jaeger_test", jaeger_conn.JaegerTest)

	//@todo 记录请求超时的路由
	var testCtl = new(test.TestController)
	var ActiveCtl = new(active.ActiveController)
	var ChanCtl = new(_chan.ChanController)
	var wsCtl = new(ws.WsController)

	Test := engine.Group("/test")
	Test.Use(requestid.SetUp(),limiter.SetUp(1),jwt.JWT(),cors.CORS(cors.CORSOptions{}))
	{
		Test.GET("/Get", testCtl.Get)
		Test.POST("/Add", testCtl.Add)
		Test.POST("/Upt", testCtl.Upt)
		Test.POST("/Del", testCtl.Del)
		Test.GET("/Redis", testCtl.RedisTest)
		Test.GET("/http", testCtl.HttpGet)
		// 测试 MD5 组合 的性能
		Test.GET("/md5", test.Md5Test)
		// 测试 AES 的性能
		Test.GET("/aes", test.AesTest)
		// 测试 RSA 的性能
		Test.GET("/rsa", test.RsaTest)
		// 测试 RSA 的性能
		Test.GET("/get_token", testCtl.GetToken)
	}

	//@todo 活动
	Active := engine.Group("/act")
	{
		Active.GET("/Get", ActiveCtl.GetActiveLeftMoney) //周剩余资金
		Active.GET("/Getlist", ActiveCtl.GetList)	//获取活动列表
		Active.GET("/active", ActiveCtl.Active) //添加活动
	}

	//@todo 协程
	Chan := engine.Group("/chan")
	{
		Chan.GET("/test", ChanCtl.Test)
	}



	Ws := engine.Group("/ws")
	{

		Ws.GET("/ws", func(c *gin.Context) {
			wsCtl.WsHandler(c.Writer, c.Request)
		})

	}



}
